package com.study2.DouDiZhu;

import java.util.*;

public class PokerGame2 {
    private static HashMap<Integer, String> pokerList = new HashMap<>();
    private static ArrayList<Integer> pokerCode = new ArrayList<>();
    
    // 初始化牌库
    static {
        String[] color = {"♥", "♠", "♣", "♦"};
        String[] number = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        int num = 1;
        for (String n : number) {
            for (String c : color) {
                pokerList.put(num , c+n);
                pokerCode.add(num);
                num++;
            }
        }
        pokerList.put(num , "小王");
        pokerCode.add(num);
        num++;
        pokerList.put(num , "大王");
        pokerCode.add(num);
    }
    
    public PokerGame2() {
        System.out.println("牌库：");
        System.out.println(pokerList);
        System.out.println(pokerCode);
        
        // 洗牌
        Collections.shuffle(pokerCode);
        
        // 发牌
        TreeSet<Integer> Lord = new TreeSet<>();
        TreeSet<Integer> player1 = new TreeSet<>();
        TreeSet<Integer> player2 = new TreeSet<>();
        TreeSet<Integer> player3 = new TreeSet<>();
        for (int i = 0; i < pokerCode.size(); i++) {
            if(i < 3){
                Lord.add(pokerCode.get(i));
                continue;
            }
            switch (i % 3) {
                case 0:
                    player1.add(pokerCode.get(i));
                    break;
                case 1:
                    player2.add(pokerCode.get(i));
                    break;
                case 2:
                    player3.add(pokerCode.get(i));
                    break;
            }
        }
        
        lookPoker("地主牌", Lord);
        lookPoker("玩家1", player1);
        lookPoker("玩家2", player2);
        lookPoker("玩家3", player3);
    }
    
    public void lookPoker(String name, TreeSet<Integer> list) {
        System.out.println(name);
        list.forEach(i -> System.out.print(pokerList.get(i) + " "));
        System.out.println();
    }
}
